﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.ServiceModel.DomainServices.Client;
using SilverErp.Web.DATA;

namespace SilverErp.Views
{
    public enum ListeTipleri
    {
        Stok,
        Cari
    }
    public partial class Liste : Page
    {
        ErpContext context;
        public ListeTipleri ListeTipi { get; set; }

        public Liste()
        {
            InitializeComponent();
            context = new ErpContext();
            this.Loaded += new RoutedEventHandler(Liste_Loaded);
        }

        void Liste_Loaded(object sender, RoutedEventArgs e)
        {
            if (this.NavigationContext.QueryString.ContainsKey("ListeTipi"))
            {
                this.ListeTipi = (ListeTipleri)Enum.Parse(typeof(ListeTipleri), this.NavigationContext.QueryString["ListeTipi"], false);
                switch (ListeTipi)
                {
                    case ListeTipleri.Stok:
                        StokListesi();
                        break;
                    case ListeTipleri.Cari:
                        break;
                    default:
                        break;
                }
            }
        }

        private void StokListesi()
        {
            EntityQuery<Stoklar> qry = context.GetStoklarsQuery();
            LoadOperation<Stoklar> operation = context.Load(qry);
            operation.Completed += (ss, oo) =>
            {
                LoadOperation<Stoklar> op = ss as LoadOperation<Stoklar>;
                if (op.HasError)
                {
                    ErrorWindow err = new ErrorWindow(op.Error);
                    err.Show();
                }
                else
                {
                    agDataGrid1.DataSource = op.Entities;
                }
            };
        }


        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

    }
}
